if ARGV.length < 1
    NUMEL = 10
else
    NUMEL = ARGV[0].to_i
end

NEAR = 1
LEFT = -1.5
RIGHT = 1.5
BOTTOM = -1.5
TOP = 1.5
RES_X = 1024
RES_Y = 768

printf("NEAR %d\n", NEAR);
printf("LEFT %d\n", LEFT);
printf("RIGHT %d\n", RIGHT);
printf("BOTTOM %d\n", BOTTOM);
printf("TOP %d\n", TOP);
printf("RES %d %d\n", RES_X, RES_Y);

#spheres
NUMEL.times do |i|
    #A random float between [10, 10], [-10, 10], and [-10, -20]
    pos = Array.new
    #pos[0] = (rand() - 0.5) * 20
    #pos[1] = (rand() - 0.5) * 20
    #pos[2] = rand()* 10 - 20
    pos[0] = (rand() - 0.5) * 5
    pos[1] = (rand() - 0.5) * 5
    pos[2] = rand()* 10 - 11

    #A random float between 0 and 5
    scaling = Array.new
    scaling[0] = rand()*5
    scaling[1] = rand()*5
    scaling[2] = rand()*5

    #A random float between 0 and 1
    color = Array.new
    color[0] = rand()
    color[1] = rand()
    color[2] = rand()

    #A random float between 0 and 1
    k = Array.new
    k[0] = rand()
    k[1] = rand()
    k[2] = rand()
    k[3] = rand()

    #A random float between 0 and 100
    n = rand(100)
    
    #A random float between 0 and 1
    transparency = rand()

    #A random value between 1 and 4, baised toward 1
    refraction = (rand()**2)*3+1

    #Half the time, no texture
    #the other half, evenly split among the available textrues
    if (rand() < 0.5)
        texture = 'none'
    else
        textures = ['anime.tga', 'ccs.tga', 'domo.tga', 'marble.tga', 'wood.tga']
        index = rand()*textures.length
        if index == textures.length
            index -= 1
        end
        texture = textures[index]
    end
    
    printf("SPHERE s%d %f %f %f %f %f %f %f %f %f %f %f %f %f %d %f %f %s\n",
        i, pos[0], pos[1], pos[2], scaling[0], scaling[1], scaling[2],
        color[0], color[1], color[2], k[0], k[1], k[2], k[3], n,
        transparency, refraction, texture)
end

#Planes
NUMEL.times do |i|
    #A random float between [10, 10], [-10, 10], and [-10, -20]
    pos = Array.new
    pos[0] = (rand() - 0.5) * 30
    pos[1] = (rand() - 0.5) * 30
    pos[2] = rand()* 10 - 40

    #A random float between 0 and 1
    normal = Array.new
    normal[0] = rand()
    normal[1] = rand()
    normal[2] = rand()

    #A random float between 0 and 1
    color = Array.new
    color[0] = rand()
    color[1] = rand()
    color[2] = rand()

    #A random float between 0 and 1
    k = Array.new
    k[0] = rand()
    k[1] = rand()
    k[2] = rand()
    k[3] = rand()

    #A random float between 0 and 100
    n = rand(100)
    
    #A random float between 0 and 1
    transparency = rand()

    #A random value between 1 and 4, baised toward 1
    refraction = (rand()**2)*3+1

    #Half the time, no texture
    #the other half, evenly split among the available textrues
    if (rand() < 0.5)
        texture = 'none'
    else
        textures = ['anime.tga', 'ccs.tga', 'domo.tga', 'marble.tga', 'wood.tga']
        index = rand()*textures.length
        if index == textures.length
            index -= 1
        end
        texture = textures[index]
    end
    
    printf("PLANE p%d %.2f %.2f %.2f %.3f %.3f %.3f %.4f %.4f %.4f %f %f %f %f %d %f %f %s\n",
        i, pos[0], pos[1], pos[2], normal[0], normal[1], normal[2],
        color[0], color[1], color[2], k[0], k[1], k[2], k[3],
        n, transparency, refraction, texture)
end

#Triangles
NUMEL.times do |i|
    #A random float between [10, 10], [-10, 10], and [-10, -20]
    pos1 = Array.new
    pos1[0] = (rand() - 0.5) * 30
    pos1[1] = (rand() - 0.5) * 30
    pos1[2] = rand()* 10 - 40

    pos2 = Array.new
    pos2[0] = (rand() - 0.5) * 30
    pos2[1] = (rand() - 0.5) * 30
    pos2[2] = rand()* 10 - 40

    pos3 = Array.new
    pos3[0] = (rand() - 0.5) * 30
    pos3[1] = (rand() - 0.5) * 30
    pos3[2] = rand()* 10 - 40

    #A random float between 0 and 1
    color = Array.new
    color[0] = rand()
    color[1] = rand()
    color[2] = rand()

    #A random float between 0 and 1
    k = Array.new
    k[0] = rand()
    k[1] = rand()
    k[2] = rand()
    k[3] = rand()

    #A random float between 0 and 100
    n = rand(100)
    
    #A random float between 0 and 1
    transparency = rand()

    #A random value between 1 and 4, baised toward 1
    refraction = (rand()**2)*3+1

    #Half the time, no texture
    #the other half, evenly split among the available textrues
    if (rand() < 0.5)
        texture = 'none'
    else
        textures = ['anime.tga', 'ccs.tga', 'domo.tga', 'marble.tga', 'wood.tga']
        index = rand()*textures.length
        if index == textures.length
            index -= 1
        end
        texture = textures[index]
    end
    
    printf("TRIANGLE t%d %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.4f %.4f %.4f %f %f %f %f %d %f %f %s\n",
        i, pos1[0], pos1[1], pos1[2], pos2[0], pos2[1], pos2[2],
        pos3[0], pos3[1], pos3[2], color[0], color[1], color[2],
        k[0], k[1], k[2], k[3], n, transparency, refraction, texture)
end

#Lights
NUMEL.times do |i|
    #A random integer between the specified boundaries
    pos = Array.new
    pos[0] = rand(RIGHT-LEFT) + LEFT
    pos[1] = rand(TOP-BOTTOM) + BOTTOM
    pos[2] = rand(TOP) + NEAR   #this is arbitrary

    #A random float between 0 and 1
    intensity = Array.new
    intensity[0] = 1-rand()
    intensity[1] = 1-rand()
    intensity[2] = 1-rand()

    printf("LIGHT l%d %d %d %d %f %f %f\n", i, pos[0], pos[1], pos[2],
        intensity[0], intensity[1], intensity[2])
end

printf("BACK 1 1 1\n")
printf("AMBIENT 0.2 0.2 0.2\n")
#printf("OUTPUT testRandom%d.ppm\n\n", NUMEL)
printf("OUTPUT testRandomClose%d.ppm\n\n", NUMEL)
